package [package].service.impl;

import [package].mapper.[Table2]Mapper;
import [package].service.[Table2]Service;
import [path_1].[path_2].common.exception.CustomException;
import [path_1].[path_2].model.[path_3].dtos.[Table2]Dto;
import [path_1].[path_2].model.[path_3].pojos.[Table2];
import [path_1].[path_2].model.common.dtos.PageResponseResult;
import [path_1].[path_2].model.common.dtos.ResponseResult;
import [path_1].[path_2].model.common.enums.AppHttpCodeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @Version: V1.0
 */
@Service
public class [Table2]ServiceImpl extends ServiceImpl<[Table2]Mapper, [Table2]> implements [Table2]Service {

    /**
     * 查询列表
     * @param dto
     * @return
     */
    @Override
    public ResponseResult findPage([Table2]Dto dto) {
        //1 参数检查
        if (dto == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        // 分页检查
        dto.checkParam();

        //2 执行查询
        // 分页
        Page page = new Page(dto.getPage(), dto.getSize());
        // 条件查询
        LambdaQueryWrapper<[Table2]> wraaper = new LambdaQueryWrapper<>();

<条件查询.String.txt>
<条件查询.Integer.txt>

        IPage pageResult = page(page, wraaper);

        //3 封装分页结果
        return PageResponseResult.page(dto.getPage(), dto.getSize(),
                (int) pageResult.getTotal(),pageResult.getRecords());
    }

    /**
     * 新增
     * @param [table2]
     * @return
     */
    @Override
    public ResponseResult insert([Table2] [table2]) {
        //1 参数检查
        if ([table2] == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }

        //2 执行保存
        save([table2]);
        return ResponseResult.errorResult(AppHttpCodeEnum.SUCCESS);
    }

    @Override
    public ResponseResult update([Table2] [table2]) {

        //1.检查参数
        if(null == [table2]){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }

        //2.修改
        updateById([table2]);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @Override
    public ResponseResult deleteById([keyType] [key2]) {
        //1.检查参数
        if([key2] == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        removeById([key2]);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

}
